package com.hnevc.netdemo;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerSocketDemo {

	public static void main(String[] args) throws IOException {
		
		ServerSocket serverSocket = new ServerSocket(20000);
		Socket socket = serverSocket.accept();//阻塞解除后，获取连接的socket	
		//接收数据
		InputStream in = socket.getInputStream();
		byte[] buffer = new byte[1024];
		int len = in.read(buffer);
		System.out.println("服务器端接收到:"+new String(buffer,0,len));
		socket.shutdownInput();
		//发送数据
		OutputStream out = socket.getOutputStream();
		String data="send ok!";
		out.write(data.getBytes());
		
		out.close();
		in.close();
		socket.close();
	}

}
